package cn.stylefeng.guns.modular.api.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.rms.model.params.OuttaskApplyParam;
import cn.stylefeng.guns.modular.rms.model.params.OuttaskParam;
import cn.stylefeng.guns.modular.rms.model.result.OuttaskApplyResult;
import cn.stylefeng.guns.modular.rms.model.result.OuttaskResult;
import cn.stylefeng.guns.modular.rms.service.OuttaskApplyService;
import cn.stylefeng.guns.modular.rms.service.OuttaskService;
import cn.stylefeng.guns.modular.wms.entity.ApplyLog;
import cn.stylefeng.guns.modular.wms.model.params.ApplyLogParam;
import cn.stylefeng.guns.modular.wms.model.params.ApplyReadParam;
import cn.stylefeng.guns.modular.wms.model.result.ApplyLogResult;
import cn.stylefeng.guns.modular.wms.service.ApplyLogService;
import cn.stylefeng.guns.modular.wms.service.ApplyReadService;
import cn.stylefeng.guns.utils.MemberTokenUtil;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 *投递简历模块管理
 */
@Controller
@RequestMapping("/api/apply")
@Api(tags = "投递简历模块管理")
@CrossOrigin
public class ApiApplyController extends BaseController {

    @Autowired
    private ApplyLogService applyLogService;
    @Autowired
    private ApplyReadService applyReadService;

    /**
     * 查询投递列表
     */
    @ResponseBody
    @RequestMapping(value = "/getApplyList",method = RequestMethod.GET)
    @ApiOperation(value = "查询投递列表", notes = "查询投递列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页数量", dataType = "Integer", paramType = "query")
    })
    public ResponseData getApplyList(ApplyLogParam param) {
        int memberId=MemberTokenUtil.getMemberId();
        param.setMemberId(memberId);
        LayuiPageInfo pageInfo= applyLogService.findPageBySpec(param);
        return ResponseData.success(pageInfo);
    }

    /**
     * 查询投递详情
     */
    @ResponseBody
    @RequestMapping(value = "/getApplyDetail",method = RequestMethod.GET)
    @ApiOperation(value = "查询投递详情", notes = "查询投递详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query")
    })
    public ResponseData getApplyDetail(Long id) {
        ApplyLogParam param1=new ApplyLogParam();
        param1.setId(id);
        ApplyLogResult result=applyLogService.findBySpec(param1);
        return ResponseData.success(result);
    }

    /**
     * 添加/更新简历投递
     */
    @ResponseBody
    @RequestMapping(value = "/addOrUpdateApply",method = RequestMethod.POST)
    @ApiOperation(value = "添加/更新简历投递", notes = "添加/更新简历投递")
    public ResponseData addOrUpdateApply(@RequestBody ApplyLogParam param) {
        try {
            int memberId=MemberTokenUtil.getMemberId();
            param.setMemberId(memberId);
            applyLogService.update(param);
            return ResponseData.success();
        }catch (Exception e){
            return ResponseData.error(e.getMessage());
        }
    }




    /**
     * 删除简历投递
     */
    @ResponseBody
    @RequestMapping(value = "/deleteApply",method = RequestMethod.POST)
    @ApiOperation(value = "删除简历投递", notes = "删除简历投递")
    public ResponseData deleteApply(@RequestBody ApplyLogParam param) {
        try {
            applyLogService.removeById(param.getId());
            return ResponseData.success();
        }catch (Exception e){
            return ResponseData.error(e.getMessage());
        }
    }

    /**
     * 添加/更新阅读记录
     */
    @ResponseBody
    @RequestMapping(value = "/addApplyRead",method = RequestMethod.POST)
    @ApiOperation(value = "添加/更新简历阅读记录", notes = "添加/更新简历阅读记录")
    public ResponseData addOrUpdateApply(@RequestBody ApplyReadParam param) {
        try {
            int memberId=MemberTokenUtil.getMemberId();
            param.setMemberId(memberId);
            applyReadService.update(param);
            return ResponseData.success();
        }catch (Exception e){
            return ResponseData.error(e.getMessage());
        }
    }

    /**
     * 更新简历状态（企业端操作）
     */
    @ResponseBody
    @RequestMapping(value = "/updateApplyStatus",method = RequestMethod.POST)
    @ApiOperation(value = "更新简历状态", notes = "更新简历状态")
    public ResponseData updateApplyStatus(@RequestBody ApplyLogParam param) {
        try {
            applyLogService.updateApplyStatus(param);
            return ResponseData.success();
        }catch (Exception e){
            return ResponseData.error(e.getMessage());
        }
    }

}



